package com.uwang.library.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.uwang.library.service.BorrowedRecordService;
import com.uwang.library.service.IndexCountService;
import com.uwang.library.service.impl.BorrowedRecordServiceImpl;
import com.uwang.library.service.impl.IndexCountServiceImpl;

@WebServlet("/indexCount")
public class IndexCountServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doGet(req, resp);
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		IndexCountService indexCountServlet = new IndexCountServiceImpl();
		resp.setContentType("text/html; charset=utf-8");
		PrintWriter out = resp.getWriter();
		// 将JAVA对象给fastjson转换
		String json = JSON.toJSONString(indexCountServlet.getCount());
		out.write(json);
		out.flush();
		out.close();
	}
	
//	public static void main(String[] args) {
//		IndexCountService indexCountServlet = new IndexCountServiceImpl();
//		Map<String, Object> count = indexCountServlet.getCount();
//		Object object = count.get("countNumber");
//		System.out.println(object);
//	}

}
